Conditional statements

- Boolean expressions
- Boolean operators

Example#1: Wages.java (if-else)
Example#2: Guessing.java

- Conditional operator (? :)

int val1 = 12, val2 = 13;
int max;

if(val1 > val2) {
	max = val1;
} else {
	max = val2;
}


max = (val1 > val2) ? val1 : val2;


System.out.println ("Your change is " + count + ((count == 1) ? "Dime" : "Dimes"));

Rewrite this using if-else

System.out.print("Your change is " + count)
if (count == 1) {
	System.out.println(" dime");
} else {
	System.out.println(" dimes");
}

- Nested ifs

if()
	if()
	
	else
else

Rule: the else is matched to the closest unmatched if


if (code == ‘R’) {
	if (height <= 20)
		System.out.println(“Situation Normal”); 
} else 
		System.out.println (“Bravo”);

In this case, Bravo is printed when code is != R

Example#3: MinOfThree.java






















